﻿using System;

using NUnit.Framework;

using TypeMock;
using TypeMock.ArrangeActAssert;

using StructureMap.TypeMockAutoMocker;

namespace StructureMap.TypeMockAutoMocker
{
	[TestFixture]
	public class FactoryTester
	{
		#region Setup/Teardown

		[SetUp]
		public void SetUp()
		{
			MockManager.Init();
			_factory = new TypeMockFactory();
		}

		#endregion

		private TypeMockFactory _factory;

		[Test]
		public void CanCreateFakeInstanceOfAConcreteTypeThatCallsOriginalImplementation()
		{
			var consumer = (ConcreteCutWithAbstractMock)_factory.CreateFakeInstanceThatCallsToOriginalImplememtation(typeof(ConcreteCutWithAbstractMock), new ConcreteProvider());

			// Should behave like a Fake and return the value of the concrete implementation
			Assert.AreEqual(8, consumer.Get8(), "the fake didn't return the value provided by the concrete implementation");
		}

		[Test]
		public void CanCreateFakeInstanceOfAAbstractTypeThatReturnsDefaultValues()
		{
			var consumer = (AbstractCutWithAbstractMock)_factory.CreateFakeInstanceThatReturnsDefaultValues(typeof(AbstractCutWithAbstractMock), new ConcreteProvider());

			// Should behave like a Fake if it's known to TypeMock 
			consumer.CallMock(1);
			Isolate.Verify.WasCalledWithExactArguments((() => consumer.CallMock(1)));


			// Should behave like a Fake and return a default value
			Assert.AreEqual(0, consumer.Get8(), "the fake didn't return the default value");
		}

		
	}
}